package com.maomao.maomaochong_i.productPackage;

import android.app.Fragment;
import android.os.Bundle;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.maomao.maomaochong_i.R;
import com.maomao.maomaochong_i.dataBean.ADInfo;

import java.util.ArrayList;
import java.util.List;

import static android.support.v4.view.PagerAdapter.POSITION_NONE;

/**
 * Created by maomao on 2017/5/17.
 * 实现可循环，可轮播的viewpager 
 */

public class ProductCycleViewPager extends Fragment implements
        ViewPager.OnPageChangeListener{

    private List<ImageView> imageViews = new ArrayList<ImageView>();
    //指示器
    private LinearLayout indicatorLayout;
    //指示圆点
    private ImageView[]  indicators;
    private FrameLayout viewPagerFrameLayout;
    private BaseViewPager viewPager;
    private BaseViewPager parentViewPager;
    private PCViewPagerAdapter adaper;
    private CycleViewPagerHandler handler;
    //创建接口对象
    private ImageCycleViewListener imageListener;
    private List<ADInfo> infos;

    //默认轮播时间
    private int time = 5000;
    //轮播当前位置
    private int currentPosition = 0;
    //滚动框是否滚动着
    private  boolean isScrolling = false;
    //是否循环
    private  boolean isCycle = false;
    //是否轮播
    private  boolean isWheel = false;
    //手指松开、页面不滚动时间，防止手机松开后短时间进行切换 
    private long releaseTime = 0;
    //转动
    private int WHEEL = 100;
    //等待
    private int WHEEL_WAIT = 101;


    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState){
        View view = LayoutInflater.from(getActivity()).inflate(
                R.layout.view_cycle_viewpager_contet,null);

        //1

        return view;
    }

    public void setData(List<ImageView> views, List<ADInfo> list,
                        ImageCycleViewListener listener){
        //2

    }

    public void setData(List<ImageView> views, List<ADInfo> list,
                        ImageCycleViewListener listener,
                        int showPosition){

        //3
    }

    //设置指示器居中，默认指示器在右方
    public void setIndicatorCenter(){

        //4
    }


    //是否循环，默认不开启，
    // 开启前，请将views的最前面与最后面各加入一个视图，用于循环 
    public void setCycle(boolean isCycle){

        //5
    }

    //是否处于循环状态 
    public boolean isCycle(){
        return isCycle;
    }

    //设置是否轮播，默认不轮播,轮播一定是循环的 
    public void setWheel(boolean isWheel){

        //6
    }

    //是否处于轮播状态 
    public boolean isWheel(){
        return isWheel;
    }

    //线程
    final Runnable runnable = new Runnable() {
        @Override
        public void run() {

            //7
        }
    };

    //释放指示器高度，可能由于之前指示器被限制了高度，此处释放 
    public void releaseHeight(){

        //18
    }

    //设置轮播暂停时间，即没多少秒切换到下一张视图.默认5000ms(毫秒/单位)
    public void  setTime(int time){
        //19
    }


    //刷新数据，当外部视图更新后，通知刷新数据 
    public void refreshData(){
        //10
    }

    //隐藏CycleViewPager 
    public void hide(){

        //11
    }

    //返回内置的viewpager
    public BaseViewPager getViewPager(){
        return viewPager;
    }

    //页面适配器 返回对应的view 
    private class PCViewPagerAdapter extends PagerAdapter {
        public int getCount(){
            return imageViews.size();
        }

        public boolean isViewFromObject(View arg0, Object arg1){
            return arg0 == arg1;
        }

        public void destroyItem(ViewGroup container, int position, Object object){
            //12
        }

        public View instantiateItem(ViewGroup container, final int position){
            ImageView v = imageViews.get(position);

            //13

            return v;
        }

        public int getItemPosition(Object object){
            return POSITION_NONE;
        }
    }


    public void onPageScrollStateChanged(int arg0){

        //14

    }

    public void onPageScrolled(int arg0, float arg1, int arg2){


    }

    public void onPageSelected(int arg0){

        //15

    }

    //设置viewpager是否可以滚动 
    public void setScrollable(boolean enable){
        //16

    }

    //返回当前位置,循环时需要注意返回的position包含之前在
    // views最前方与最后方加入的视图，即当前页面试图在views集合的位置 

    public int getCurrentPosition(){
        return currentPosition;
    }

    //设置指示器 
    private void setIndicator(int selectedPosition){

        //17

    }

    //如果当前页面嵌套在另一个viewPager中，为了在进行滚动时阻断父
    // ViewPager滚动，可以 阻止父ViewPager滑动事件 
    //父ViewPager需要实现ParentViewPager中的setScrollable方法 
    public void disableParentViewPagerTouchEvent(BaseViewPager parentViewPager){

        //18
    }

    //轮播控件的监听事件,一个自定义接口
    public static interface ImageCycleViewListener{
        public void onImageClick(ADInfo info, int position, View imageView);
    }
}
